// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   UserInfo.java

package include.nseer_cookie;

import include.nseer_db.nseer_db_backup;
import include.operateXML.Reading;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.http.*;

// Referenced classes of package include.nseer_cookie:
//			getTime

public class UserInfo
	implements Serializable, HttpSessionBindingListener
{

	private String userName;
	private String userTag;
	private String id;
	private String unit;

	public UserInfo(String unit, String uName, String uTag, String id)
	{
		userName = "";
		userTag = "";
		this.id = "";
		this.unit = "";
		userName = uName;
		userTag = uTag;
		this.id = id;
		this.unit = unit;
	}

	public void valueBound(HttpSessionBindingEvent event)
	{
		HttpSession session = event.getSession();
		ServletContext ctx = session.getServletContext();
		Map map = (Map)ctx.getAttribute("user");
		if (map == null)
		{
			map = new HashMap();
			ctx.setAttribute("user", map);
		}
		map.put((new StringBuilder(String.valueOf(unit))).append("&").append(userName).append("&").append(userTag).toString(), (new StringBuilder(String.valueOf(unit))).append("&").append(userName).append("&").append(userTag).toString());
		System.out.println((new StringBuilder(String.valueOf(unit))).append("&").append("userName:").append(userName).append("&").append(userTag).append(" enter").toString());
	}

	public void valueUnbound(HttpSessionBindingEvent event)
	{
		HttpSession session = event.getSession();
		ServletContext ctx = session.getServletContext();
		Map map = (Map)ctx.getAttribute("user");
		map.remove((new StringBuilder(String.valueOf(unit))).append("&").append(userName).append("&").append(userTag).toString());
		String xmlFile_s = (new StringBuilder("xml/include/listPage/")).append(userName).append(userTag).append(".xml").toString();
		Reading reader = new Reading(xmlFile_s);
		String path = ctx.getRealPath("/");
		String dbase = reader.getAttributeByTable("database", (new StringBuilder("name:")).append(userName).toString());
		writeDB(dbase, ctx);
		File f = new File((new StringBuilder(String.valueOf(path))).append(xmlFile_s).toString());
		String count = (String)ctx.getAttribute(unit);
		count = (new StringBuilder(String.valueOf(Integer.parseInt(count) - 1))).toString();
		ctx.setAttribute(unit, count);
		System.out.println((new StringBuilder(String.valueOf(unit))).append("&").append("userName:").append(userName).append("&").append(userTag).append(" out").toString());
	}

	private void writeDB(String unit_db_name, ServletContext dbApplication)
	{
		nseer_db_backup erp_db = new nseer_db_backup(dbApplication);
		String time = (new getTime()).getTime("yyyy-MM-dd HH:mm:ss");
		try
		{
			if (erp_db.conn(unit_db_name))
			{
				String sql2 = (new StringBuilder("update security_alive_access set time2='")).append(time).append("' where id='").append(id).append("'").toString();
				erp_db.executeUpdate(sql2);
				erp_db.close();
			} else
			{
				System.out.println("i am sorry!");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
